﻿using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
using UnityTouchTable.Runtime;

namespace UnityTouchTable.Editor
{
    [CustomEditor(typeof(MarkerItemBase), true)]
    [CanEditMultipleObjects]
    public class MarkerItemBaseEditor : TouchTableInspector
    {
        #region Field
        private MarkerItemBase m_MarkerItemBase;

        private SerializedProperty m_ID;

        private SerializedProperty m_WorldDepth;

        private SerializedProperty m_LerpCenterPosition;

        private SerializedProperty m_MoveSpeed;
        #endregion

        #region Function
        protected virtual void OnEnable()
        {
            this.m_MarkerItemBase = this.serializedObject.targetObject as MarkerItemBase;

            //ID
            this.m_ID = this.serializedObject.FindProperty("m_ID");

            //深度
            this.m_WorldDepth = this.serializedObject.FindProperty("m_WorldDepth");

            //是否插值移动中心位置
            this.m_LerpCenterPosition = this.serializedObject.FindProperty("m_LerpCenterPosition");

            //移动速度
            this.m_MoveSpeed = this.serializedObject.FindProperty("m_MoveSpeed");
        }

        public override void OnInspectorGUI()
        {
            this.serializedObject.Update();

            this.DrawMarkItemBaseProperty();

            this.serializedObject.ApplyModifiedProperties();
        }

        /// <summary>
        /// 绘制父类属性
        /// </summary>
        protected void DrawMarkItemBaseProperty()
        {
            this.m_ID.intValue = EditorGUILayout.IntSlider(new GUIContent("ID"), this.m_ID.intValue, 0, 8);

            Canvas canvas = this.m_MarkerItemBase.GetComponentInParent<Canvas>();
            RectTransform rectTransform = this.m_MarkerItemBase.GetComponent<RectTransform>();
            if (canvas == null)
            {
                if (rectTransform == null)
                {
                    this.m_WorldDepth.floatValue = EditorGUILayout.Slider(new GUIContent("深度，和相机的距离"), this.m_WorldDepth.floatValue, 0.01f, 100.0f);
                }
                else
                    EditorGUILayout.HelpBox("物体不在画布下，但有RectTransform组件，请检查你的Inspector面板", MessageType.Warning);
            }
            else
            {
                if (rectTransform == null)
                    EditorGUILayout.HelpBox("未查找到RectTransform组件，但物体在画布下，请检查你的Inspector面板", MessageType.Warning);
            }

            this.m_LerpCenterPosition.boolValue = EditorGUILayout.Toggle(new GUIContent("是否插值移动中心位置?"), this.m_LerpCenterPosition.boolValue);
            if (this.m_LerpCenterPosition.boolValue)
                this.m_MoveSpeed.floatValue = EditorGUILayout.Slider(new GUIContent("移动速度"), this.m_MoveSpeed.floatValue, 0.1f, 10.0f);
        }
        #endregion
    }
}